package glgc.jjgys.system.controller;

import glgc.jjgys.common.result.Result;
import glgc.jjgys.system.service.PBatchInsert;
import glgc.jjgys.system.utils.ReceiveUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

public abstract class BaseDataInsertController<T> {
    protected abstract PBatchInsert<T> getService();

    @PostMapping("createManyRecords")
    public Result createManyRecords(@RequestBody List<T> rawData, HttpServletRequest request) {
        String userID = ReceiveUtils.getUserIDFromRequest(request);
        if (userID == null) {
            return Result.fail("用户未登录");
        }
        int res = getService().createMoreRecords(rawData, userID);
        System.out.println(rawData);
        return Result.ok(res);
    }
}
